﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Microsoft.ReportingServices;
using Microsoft.Reporting;
using Microsoft.Reporting.WinForms;

using System.Collections.ObjectModel;

using P2.Cuberry.Framework.Helper;


namespace P2.Cuberry.Modules.Framework.LocalCuberryReport
{    
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class LocalCuberryReportsDetailsView : Window
    {   
        private System.Windows.Controls.ComboBox fyCBox = new System.Windows.Controls.ComboBox();        
        private System.Windows.Controls.ComboBox MonthComboBox = new System.Windows.Controls.ComboBox();
        
        private System.Windows.Controls.CheckBox StatusOpenCheckBox = new System.Windows.Controls.CheckBox();
        private System.Windows.Controls.CheckBox StatusBookedCheckBox = new System.Windows.Controls.CheckBox();
        private System.Windows.Controls.ComboBox TransactionStatusCombobox = new System.Windows.Controls.ComboBox();
        
        private System.Windows.Controls.DatePicker DateStartDatePicker = new System.Windows.Controls.DatePicker();
        private System.Windows.Controls.DatePicker DateEndDatePicker = new System.Windows.Controls.DatePicker();

        private System.Windows.Controls.ComboBox AccountTypeComboBox = new System.Windows.Controls.ComboBox();
        private System.Windows.Controls.ComboBox AccountLevelComboBox = new System.Windows.Controls.ComboBox();

        private System.Windows.Controls.TextBox AccountNoTexBox = new System.Windows.Controls.TextBox();
        private System.Windows.Controls.ListBox AccountNoListBox = new System.Windows.Controls.ListBox();
        private System.Windows.Controls.ComboBox AccountNoComboBox = new System.Windows.Controls.ComboBox();
        private System.Windows.Controls.TextBox AccountNameOrNoSearchTextBox = new System.Windows.Controls.TextBox();
        
        private System.Windows.Controls.TextBox DocumentNoTextBox = new System.Windows.Controls.TextBox();
        private System.Windows.Controls.TextBox DescriptionHeaderTextBox = new System.Windows.Controls.TextBox();
        private System.Windows.Controls.TextBox DescriptionItemTextBox = new System.Windows.Controls.TextBox();

        private P2.Cuberry.Modules.Framework.LocalCuberryReport.Controls.ComboWithCheckboxes MyComboWithCheckboxes = new Controls.ComboWithCheckboxes();
        
        
        private BusinessEntities.LCReport localCuberryReport;
       

        public LocalCuberryReportsDetailsView(BusinessEntities.LCReport xlocalCuberryReport)
        {
            InitializeComponent();

            this.localCuberryReport = xlocalCuberryReport;            
            PrepareReport();
        }


        private void PrepareReport()
        {            
            reportViewer1.ProcessingMode = ProcessingMode.Local;
            localCuberryReport.ReportDataSet.BeginInit();            

            this.reportViewer1.LocalReport.DataSources.Add(initReportDataSource());
            loadReport();

            localCuberryReport.ReportDataSet.EndInit();

            switch (localCuberryReport.ReportName)
            {
                case "0101ChartOfAccounts":
                    PrepareReport0101();
                    break;

                case "02 Profit and Loss Year to Month":
                    PrepareReport0201();
                    break;

                case "02 Profit and Loss One Year":
                    PrepareReport0202();
                    break;                

                case "0301 Trial Balance One Year":
                    PrepareReport031(false);
                    break;

                case "0302 Trial Balance One Year General":
                    PrepareReport031(false); //it's using the same base
                    break;

                case "0303 Trial Balance One Year One Level":
                    PrepareReport031(true); //it's using the same basis, but with parameter AccountNo
                    break;

                case "0304 Trial Balance Year to Month":
                    PrepareReport032(false);
                    break;

                case "0305 Trial Balance Year to Month General":
                    PrepareReport032(false); //it's using the same base
                    break;

                case "0306 Trial Balance Year to Month One Level":
                    PrepareReport032(true); //it's using the same base
                    break;

                case "04 Balance Sheet One Year":
                    PrepareReport0401();
                    // Add a handler for drillthrough.
                    //reportViewer1.Drillthrough += new DrillthroughEventHandler(DrillthroughEventHandlerR08);
                    break;

                case "04 Balance Sheet Year to Month Account Type":
                    PrepareReport0402();
                    break;

                case "04 Balance Sheet Year to Month":
                    PrepareReport0403(); //InitReport09();
                    break;

                case "05 Account Statement Account Range II":
                    PrepareReport0501(); //InitReport10();
                    break;

                case "05 Account Statement Account Range":
                    PrepareReport051(true); //InitReport05AccountRange(true);
                    break;

                case "05 Account Statement Grouped by Month":
                    PrepareReport052(); //InitReport05AccountStatementGroupeBbyMonth();
                    break;

                case "06 General Ledger Accounts Overview Account Range":
                    PrepareReport051(true); //InitReport05AccountRange(true);
                    break;

                case "06 General Ledger All Accounts Overview":
                    PrepareReport051(false); //InitReport05AccountRange(false);
                    break;

                case "0701 Journal One Account II":
                    PrepareReport0701();
                    break;

                case "0702 Journal All Accounts Range Grouped II":
                    PrepareReport0702();
                    break;

                case "0703 Journal All Accounts Range II": //??
                    PrepareReport0703();
                    break;

                case "0704 Journal One Account":
                    PrepareReport0704();
                    break;

                case "0705 Journal All Accounts Range Grouped":
                    PrepareReport0705();
                    break;

                case "0706 Journal All Accounts Range":
                    PrepareReport0706();
                    break;

                case "0707 Journal Transaction Header Grouped":
                    PrepareReport0707(); //this.InitReport0707();
                    break;
            }
        }


        private void ReportRunBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {             
                switch (localCuberryReport.ReportName)
                {
                    case "0101ChartOfAccounts":
                        RunReport0101();
                        break;

                    case "02 Profit and Loss Year to Month":
                        RunReport0201();
                        break;

                    case "02 Profit and Loss One Year":
                        RunReport0202();
                        break;
                                           

                    case "0301 Trial Balance One Year":
                        RunReport031(false);
                        break;

                    case "0302 Trial Balance One Year General":
                        RunReport031(false);
                        break;

                    case "0303 Trial Balance One Year One Level":
                        RunReport031(true);
                        break;

                    case "0304 Trial Balance Year to Month":
                        RunReport032(false);
                        break;

                    case "0305 Trial Balance Year to Month General":
                        RunReport032(false);
                        break;

                    case "0306 Trial Balance Year to Month One Level":
                        RunReport032(true);
                        break;

                    case "04 Balance Sheet One Year":
                        RunReport0401();
                        break;

                    case "04 Balance Sheet Year to Month Account Type":
                        RunReport0402();
                        break;

                    case "04 Balance Sheet Year to Month":
                        RunReport0403();
                        break;

                    case "05 Account Statement Account Range II":
                        RunReport0501();
                        break;

                    case "05 Account Statement Account Range":
                        RunReport051(true);
                        break;

                    case "05 Account Statement Grouped by Month":
                        RunReport052();
                        break;

                    case "06 General Ledger Accounts Overview Account Range":
                        RunReport051(true);
                        break;

                    case "06 General Ledger All Accounts Overview":
                        RunReport0601();
                        break;

                    case "0701 Journal One Account II":
                        RunReport0701();
                        break;

                    case "0702 Journal All Accounts Range Grouped II":
                        RunReport0702();
                        break;

                    case "0703 Journal All Accounts Range II": //??
                        RunReport0703();
                        break;

                    case "0704 Journal One Account":
                        RunReport0704();
                        break;

                    case "0705 Journal All Accounts Range Grouped":
                        RunReport0705();
                        break;

                    case "0706 Journal All Accounts Range":
                        RunReport0706();
                        break;

                    case "0707 Journal Transaction Header Grouped":
                        RunReport0707();
                        break;

                    default:
                        if (localCuberryReport.ReportName == null)
                        {
                            //MessageBox.Show("Report not found");
                            //messageStack.Add(new P2TransactionMessage(this.ValidationType, P2Translator.GetResource("Validation_Report_Not_Found")));
                        }
                        break;
                }
                

                this.reportViewer1.LocalReport.SetParameters(localCuberryReport.ReportParameterList);
                reportViewer1.RefreshReport();
            }
            catch (System.Exception ex) //AM:TC
            {
                P2ExceptionHandler.LogException(ex, string.Format("{0}.{1}", this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name));
            }
        }


        #region Prepare & Run

        private void PrepareReport0101()
        {            
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);                    
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23)); 
        }

        private void RunReport0101()
        {            
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            //localCuberryReport.ReportRun(fiscalYear);

            P2CuberryDataSetTableAdapters.DS1TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DS1TableAdapter();
            tableAdapter.ClearBeforeFill = true;
            tableAdapter.Fill(localCuberryReport.ReportDataSet.DS1, fiscalYear);
            
            ReportParameter rp = new ReportParameter("FiAccountFiscalYearID", fiscalYear.ToString(), true);
            localCuberryReport.ReportParameterList.Add(rp);
        }


        private void PrepareReport0201()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);            
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlMonthComboBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalMonthL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlStatusOpen(new Thickness(236, 6, 0, 0), 130, 23);
            addControlStatusBooked(new Thickness(236, 36, 0, 0), 130, 23);
        }

        private void RunReport0201()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.IsChecked );
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.IsChecked);
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;            
                                    
            P2CuberryDataSetTableAdapters.DataTable4TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable4TableAdapter();
            tableAdapter.ClearBeforeFill = true;                                   

            if (this.fyCBox.SelectedValue != null)
            {
                tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable4, fiscalYear, bookingMonth, statusOpen, statusBooked);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", fiscalYear.ToString(), true); //toDo:this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem)
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString(), true);
                //this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter, monthParameter });
                localCuberryReport.ReportParameterList.Add(fyParameter);
                localCuberryReport.ReportParameterList.Add(monthParameter);
            }
        }
        

        ///////////
        private void PrepareReport0202()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlStatusOpen(new Thickness(236, 6, 0, 0), 130, 23);
            addControlStatusBooked(new Thickness(236, 36, 0, 0), 130, 23);            
        }

        private void RunReport0202()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.IsChecked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.IsChecked);                        

            P2CuberryDataSetTableAdapters.DataTable3TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable3TableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable3, fiscalYear, statusOpen, statusBooked);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", fiscalYear.ToString(), true);                
                localCuberryReport.ReportParameterList.Add(fyParameter);                
            }
        }


        private void PrepareReport031(bool withAccountNo)
        {
            string maxAccountLevelStr = P2.Cuberry.Framework.Helper.Configuration.ConfigurationSetUp.GetAppConfigValue("MaxAccountLevel");
            int maxAccountLevel = 5;

            if (!string.IsNullOrEmpty(maxAccountLevelStr))            
                int.TryParse(maxAccountLevelStr, out maxAccountLevel);

            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlAccountLevelComboBox(maxAccountLevel, new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountLevelL", new Thickness(106, 5, 0, 0), 80, 23));
            
            if (withAccountNo)
            {
                addControlAccountNoTexBox(new Thickness(206, 28, 0, 0), 80, 23);
                FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(206, 5, 0, 0), 80, 23));

                addControlStatusOpen(new Thickness(306, 6, 0, 0), 130, 23);
                addControlStatusBooked(new Thickness(306, 36, 0, 0), 130, 23);
            }
            else
            {
                addControlStatusOpen(new Thickness(206, 6, 0, 0), 130, 23);
                addControlStatusBooked(new Thickness(206, 36, 0, 0), 130, 23);
            }
        }

        private void RunReport031(bool withAccountNo)
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.IsChecked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.IsChecked);
            int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            string accountNo = this.AccountNoTexBox.Text;

            P2CuberryDataSetTableAdapters.DataTable5TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable5TableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                if (withAccountNo)
                {
                    tableAdapter.FillByAccountNo(localCuberryReport.ReportDataSet.DataTable5, accountNo, fiscalYear, accountLevel, statusOpen, statusBooked);
                }
                else
                {
                    tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable5, fiscalYear, accountLevel, statusOpen, statusBooked);
                }
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", fiscalYear.ToString(), true); //this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem)                
                localCuberryReport.ReportParameterList.Add(fyParameter);
            }            
        }

        //---------

        private void PrepareReport032(bool withAccountNo)
        {           
            string maxAccountLevelStr = P2.Cuberry.Framework.Helper.Configuration.ConfigurationSetUp.GetAppConfigValue("MaxAccountLevel");
            int maxAccountLevel = 5;

            if (!string.IsNullOrEmpty(maxAccountLevelStr))
                int.TryParse(maxAccountLevelStr, out maxAccountLevel);

            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));
                        
            addControlMonthComboBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalMonthL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlAccountLevelComboBox(maxAccountLevel, new Thickness(206, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountLevelL", new Thickness(206, 5, 0, 0), 80, 23));
            //accountType
            
            if (withAccountNo)
            {
                addControlAccountNoTexBox(new Thickness(306, 28, 0, 0), 80, 23);
                FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(306, 5, 0, 0), 80, 23));

                addControlStatusOpen(new Thickness(406, 6, 0, 0), 130, 23);
                addControlStatusBooked(new Thickness(406, 36, 0, 0), 130, 23);
            }
            else
            {
                addControlStatusOpen(new Thickness(306, 6, 0, 0), 130, 23);
                addControlStatusBooked(new Thickness(306, 36, 0, 0), 130, 23);
            }
        }

        private void RunReport032(bool withAccountNo) //ToDo: ParentAccount Parameter
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.IsChecked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.IsChecked);
            int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            string accountNo = this.AccountNoTexBox.Text;
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;            

            P2CuberryDataSetTableAdapters.DataTable6TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable6TableAdapter();
            tableAdapter.ClearBeforeFill = true;
            
            if (this.fyCBox.SelectedValue != null)
            {
                if (withAccountNo)
                {
                    tableAdapter.FillByAccountNo(localCuberryReport.ReportDataSet.DataTable6, accountNo, fiscalYear, bookingMonth, accountLevel, statusOpen, statusBooked);
                }
                else
                {
                    tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable6, fiscalYear, bookingMonth, accountLevel, statusOpen, statusBooked);

                    //P2CuberryDataSetTableAdapters.FiAccountTableAdapter tableAdapterFiAcc = new P2CuberryDataSetTableAdapters.FiAccountTableAdapter();
                    ////tableAdapterFiAcc.ClearBeforeFill = true;
                    //tableAdapterFiAcc.FillByAccountNo();
                }
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", fiscalYear.ToString(), true); 
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString(), true);

                localCuberryReport.ReportParameterList.Add(fyParameter);
                localCuberryReport.ReportParameterList.Add(monthParameter);
            } 
        }
        //---------


        private void PrepareReport0401()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlStatusOpen(new Thickness(136, 6, 0, 0), 130, 23);
            addControlStatusBooked(new Thickness(136, 36, 0, 0), 130, 23);
        }

        private void RunReport0401()
        {            
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.IsChecked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.IsChecked);

            P2CuberryDataSetTableAdapters.DataTable7TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable7TableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable7, fiscalYear, statusOpen, statusBooked);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", fiscalYear.ToString(), true);
                localCuberryReport.ReportParameterList.Add(fyParameter);
            }
        }
        //---------

        private void PrepareReport0402()
        {
            string maxAccountLevelStr = P2.Cuberry.Framework.Helper.Configuration.ConfigurationSetUp.GetAppConfigValue("MaxAccountLevel");
            int maxAccountLevel = 5;

            if (!string.IsNullOrEmpty(maxAccountLevelStr))
                int.TryParse(maxAccountLevelStr, out maxAccountLevel);

            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlMonthComboBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalMonthL", new Thickness(106, 5, 0, 0), 80, 23));
                        
            addControlAccountLevelComboBox(maxAccountLevel, new Thickness(206, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountLevelL", new Thickness(206, 5, 0, 0), 80, 23));

            addControlAccountTypeComboBox(new Thickness(306, 28, 0, 0), 120, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountTypeL", new Thickness(306, 5, 0, 0), 80, 23));
            
            addControlStatusOpen(new Thickness(436, 6, 0, 0), 130, 23);
            addControlStatusBooked(new Thickness(436, 36, 0, 0), 130, 23);
        }

        private void RunReport0402()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.IsChecked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.IsChecked);
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            int accountType = Convert.ToInt16(this.AccountTypeComboBox.SelectedValue);
            
            P2CuberryDataSetTableAdapters.DataTable8TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable8TableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable8, accountType, fiscalYear, bookingMonth, accountLevel, statusOpen, statusBooked);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", fiscalYear.ToString(), true); //toDo:this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem)
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString(), true);
                localCuberryReport.ReportParameterList.Add(fyParameter);
                localCuberryReport.ReportParameterList.Add(monthParameter);
            }
        }
        //---------

        private void PrepareReport0403()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlMonthComboBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalMonthL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlStatusOpen(new Thickness(236, 6, 0, 0), 130, 23);
            addControlStatusBooked(new Thickness(236, 36, 0, 0), 130, 23);
        }

        private void RunReport0403() //Report is not loading!
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.IsChecked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.IsChecked);
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            //localCuberryReport.ReportRun(fiscalYear);

            P2CuberryDataSetTableAdapters.DataTable9TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable9TableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable9, fiscalYear, bookingMonth, statusOpen, statusBooked);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", fiscalYear.ToString(), true); //toDo:this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem)
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString(), true);
                localCuberryReport.ReportParameterList.Add(fyParameter);
                localCuberryReport.ReportParameterList.Add(monthParameter);
            }
        }
        //---------

        private void PrepareReport0501()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlDateStart(new Thickness(106, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(226, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(226, 5, 0, 0), 80, 23));
                        
            addControlAccountNoTexBox(new Thickness(346, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(346, 5, 0, 0), 80, 23));
        }

        private void RunReport0501()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            DateTime dateStart = this.DateStartDatePicker.SelectedDate.Value;
            DateTime dateEnd = this.DateEndDatePicker.SelectedDate.Value;
            string accountNo = this.AccountNoTexBox.Text;            

            P2CuberryDataSetTableAdapters.DataTable10TableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.DataTable10TableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();
                //fyTableAdapter.ClearBeforeFill = true;
                //P2CuberryDataSetTableAdapters.DataTable6TableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.DataTable6TableAdapter();
                //fyTableAdapter.

                tableAdapter.Fill(localCuberryReport.ReportDataSet.DataTable10, fiscalYear, dateStart, dateEnd, accountNo, Convert.ToDateTime("2010-01-01")); //ToDo: Change to FY-Start-Date

                ReportParameter dateStartParameter = new ReportParameter("ParameterDateStart", dateStart.ToString(), true);
                ReportParameter dateEndParameter = new ReportParameter("ParameterDateEnd", dateEnd.ToString(), true);
                ReportParameter dateStartFYParameter = new ReportParameter("ParameterFYDateStart", dateStart.ToString(), true);
                ReportParameter dateEndFYParameter = new ReportParameter("ParameterFYDateEnd", dateEnd.ToString(), true);

                localCuberryReport.ReportParameterList.Add(dateStartParameter);
                localCuberryReport.ReportParameterList.Add(dateEndParameter);
                localCuberryReport.ReportParameterList.Add(dateStartFYParameter);
                localCuberryReport.ReportParameterList.Add(dateEndFYParameter);
            }
        }
        //---------

        private void PrepareReport051(bool withAccountNo)
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlDateStart(new Thickness(106, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(226, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(226, 5, 0, 0), 80, 23));

            if (withAccountNo)
            {
                addControlAccountNoTexBox(new Thickness(346, 28, 0, 0), 80, 23);
                FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(346, 5, 0, 0), 80, 23));
            }
        }

        private void RunReport051(bool withAccountNo)
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            DateTime dateStart = this.DateStartDatePicker.SelectedDate.Value;
            DateTime dateEnd = this.DateEndDatePicker.SelectedDate.Value;
            string accountNo = this.AccountNoTexBox.Text;

            P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();
                
                if (withAccountNo)
                {
                    tableAdapter.Fill(localCuberryReport.ReportDataSet.FiAccountStatementAccountRangeDataTable, fiscalYear, dateStart, dateEnd, accountNo);
                }                
            }
        }
        //---------

        private void PrepareReport052()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlDateStart(new Thickness(106, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(226, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(226, 5, 0, 0), 80, 23));

            addControlAccountNoListbox(5, new Thickness(346, 9, 0, 0), 140, 63); //ToDo: Change FiscalYear           
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(346, 5, 0, 0), 80, 23));

            addControlComboWithCheckboxes(5, new Thickness(446, 28, 0, 0), 140, 23); //Just testing
            FindGrid.Children.Add(new Controls.CuberryReportLabel("MyComboWithCheckboxesL", new Thickness(446, 5, 0, 0), 80, 23));
        }

        private void RunReport052()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            DateTime dateStart = this.DateStartDatePicker.SelectedDate.Value;
            DateTime dateEnd = this.DateEndDatePicker.SelectedDate.Value;
            int accountNo = Convert.ToInt32(this.AccountNoListBox.SelectedValue); //ToDo: Must be multiple values

            P2CuberryDataSetTableAdapters.FiAccountStatementGroupByMonthDataTableTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.FiAccountStatementGroupByMonthDataTableTableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();
                tableAdapter.Fill(localCuberryReport.ReportDataSet.FiAccountStatementGroupByMonthDataTable, fiscalYear, accountNo, dateStart, dateEnd);                
            }
        }
        //---------

        // No PrepareReport0601() needed, it uses PrepareReport051(false)

        private void RunReport0601()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            DateTime dateStart = this.DateStartDatePicker.SelectedDate.Value;
            DateTime dateEnd = this.DateEndDatePicker.SelectedDate.Value;
            string accountNo = this.AccountNoTexBox.Text;
            
            P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();

                tableAdapter.FillByFiscalYear(localCuberryReport.ReportDataSet.FiAccountStatementAccountRangeDataTable, fiscalYear, dateStart, dateEnd);                
            }
        }
        //---------

        private void PrepareReport0701()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlDateStart(new Thickness(106, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(226, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(226, 5, 0, 0), 80, 23));

            addControlAccountSearchTexBox(new Thickness(346, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNameOrNoSearchTextBoxL", new Thickness(346, 5, 0, 0), 80, 23));

            //addControlAccountNoCombobox(FY, new Thickness(446, 28, 0, 0), new Thickness(446, 5, 0, 0), 80, 23, 80, 23);
        }

        private void RunReport0701()
        {
            //int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            //localCuberryReport.ReportRun(fiscalYear);
        }
        //---------

        private void PrepareReport0702()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));
            
            addControlAccountNoTexBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(106, 5, 0, 0), 80, 23));
            
            addControlDateStart(new Thickness(206, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(206, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(326, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(326, 5, 0, 0), 80, 23));
        }

        private void RunReport0702()
        {
            //int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            //localCuberryReport.ReportRun(fiscalYear);
        }
        //---------


        private void PrepareReport0703()
        {
                        
        }

        private void RunReport0703()
        {
            //int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            //localCuberryReport.ReportRun(fiscalYear);
        }
        //---------

        private void PrepareReport0704()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));
                        
            addControlAccountNoTexBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(106, 5, 0, 0), 80, 23));
                        
            addControlDateStart(new Thickness(206, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(206, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(326, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(326, 5, 0, 0), 80, 23));
                        
            addControlTransactionStatusCombobox(new Thickness(446, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("TransactionStatusComboboxL", new Thickness(446, 5, 0, 0), 80, 23));           
            
            addControlAccountSearchTexBox(new Thickness(546, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNameOrNoSearchTextBoxL", new Thickness(546, 5, 0, 0), 80, 23));

            //addControlAccountNoCombobox(FY, new Thickness(446, 28, 0, 0), new Thickness(446, 5, 0, 0), 80, 23, 80, 23);
        }

        private void RunReport0704()
        {
            //int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            //localCuberryReport.ReportRun(fiscalYear);
        }
        //---------

        private void PrepareReport0705()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlAccountNoTexBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(106, 5, 0, 0), 80, 23));
            
            addControlDateStart(new Thickness(206, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(206, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(326, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(326, 5, 0, 0), 80, 23));

            addControlTransactionStatusCombobox(new Thickness(446, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("TransactionStatusComboboxL", new Thickness(446, 5, 0, 0), 80, 23));            
        }

        private void RunReport0705()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            DateTime dateStart = this.DateStartDatePicker.SelectedDate.Value;
            DateTime dateEnd = this.DateEndDatePicker.SelectedDate.Value;
            string accountNo = this.AccountNoTexBox.Text;
            int statusID = Convert.ToInt32(this.TransactionStatusCombobox.SelectedValue);


            P2CuberryDataSetTableAdapters.JournalAllAccountsRangeGroupedDataTableTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.JournalAllAccountsRangeGroupedDataTableTableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();

                tableAdapter.Fill(localCuberryReport.ReportDataSet.JournalAllAccountsRangeGroupedDataTable, fiscalYear, dateStart, dateEnd, accountNo, statusID);
            }
        }
        //---------

        private void PrepareReport0706()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));
                        
            addControlAccountNoTexBox(new Thickness(106, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("AccountNoL", new Thickness(106, 5, 0, 0), 80, 23));
            
            addControlDateStart(new Thickness(206, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(206, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(326, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(326, 5, 0, 0), 80, 23));
                        
            addControlTransactionStatusCombobox(new Thickness(446, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("TransactionStatusComboboxL", new Thickness(446, 5, 0, 0), 80, 23));           
        }

        private void RunReport0706()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            DateTime dateStart = this.DateStartDatePicker.SelectedDate.Value;
            DateTime dateEnd = this.DateEndDatePicker.SelectedDate.Value;
            string accountNo = this.AccountNoTexBox.Text;
            int statusID = Convert.ToInt32(this.TransactionStatusCombobox.SelectedValue);
            

            P2CuberryDataSetTableAdapters.JournalAllAccountsRangeDataTableTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.JournalAllAccountsRangeDataTableTableAdapter();
            tableAdapter.ClearBeforeFill = true;

            if (this.fyCBox.SelectedValue != null)
            {
                P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();

                tableAdapter.Fill(localCuberryReport.ReportDataSet.JournalAllAccountsRangeDataTable, fiscalYear, dateStart, dateEnd, accountNo, statusID);
            }
        }
        //---------

        private void PrepareReport0707()
        {
            addControlFiscalYear(new Thickness(6, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("FiscalYearL", new Thickness(6, 5, 0, 0), 80, 23));

            addControlDateStart(new Thickness(106, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateStartDatePickerL", new Thickness(106, 5, 0, 0), 80, 23));

            addControlDateEnd(new Thickness(226, 28, 0, 0), 100, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DateEndDatePickerL", new Thickness(226, 5, 0, 0), 80, 23));
           
            addControlDocumentNoTextBox(new Thickness(346, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DocumentNoTextBoxL", new Thickness(346, 5, 0, 0), 80, 23));           

            addControlDescriptionHeaderTextBox(new Thickness(446, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DescriptionHeaderTextBoxL", new Thickness(446, 5, 0, 0), 80, 23));           

            addControlDescriptionItemTextBox(new Thickness(546, 28, 0, 0), 80, 23);
            FindGrid.Children.Add(new Controls.CuberryReportLabel("DescriptionItemTextBoxL", new Thickness(546, 5, 0, 0), 80, 23));           

        }

        private void RunReport0707()
        {
            int fiscalYear = Convert.ToInt32(this.fyCBox.SelectedValue);
            DateTime dateStart = this.DateStartDatePicker.SelectedDate.Value;
            DateTime dateEnd = this.DateEndDatePicker.SelectedDate.Value;
            string documentNo = this.DocumentNoTextBox.Text;
            string descriptionHeader = this.DescriptionHeaderTextBox.Text;
            string descriptionItem = this.DescriptionItemTextBox.Text;

            P2CuberryDataSetTableAdapters.JournalTransactionHeaderGroupedDataTableTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.JournalTransactionHeaderGroupedDataTableTableAdapter();
            tableAdapter.ClearBeforeFill = true;
            
            if (this.fyCBox.SelectedValue != null)
            {
                P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fyTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();
                
                tableAdapter.Fill(localCuberryReport.ReportDataSet.JournalTransactionHeaderGroupedDataTable, fiscalYear, dateStart, dateEnd, documentNo, descriptionHeader, descriptionItem);
            }
        }
        //---------


        ///////////

        #endregion


        # region load & init report

        private void loadReport()
        {
            string location = P2.Cuberry.Framework.Helper.Configuration.ConfigurationSetUp.GetAppConfigValue("ReportLocation");
            if (string.IsNullOrEmpty(location))
                location = @".";

            //this.reportViewer1.LocalReport.ReportEmbeddedResource = @"LocalCuberryReport.Reports." + ReportTitle + ".rdlc"; 
            this.reportViewer1.LocalReport.ReportPath = location + localCuberryReport.ReportLocation + ".rdlc"; 
        }


        private ReportDataSource initReportDataSource()
        {
            System.Windows.Forms.BindingSource dsXBindingSource = new BindingSource();
            ReportDataSource reportDataSource1 = new ReportDataSource();

            dsXBindingSource.DataMember = localCuberryReport.ReportBindingSourceDataMemberName;
            dsXBindingSource.DataSource = this.localCuberryReport.ReportDataSet;

            reportDataSource1.Name = localCuberryReport.ReportDataSourceName;
            reportDataSource1.Value = dsXBindingSource;

            return reportDataSource1;
        }

        #endregion


        #region Adding Controls

        private void addControlFiscalYear(Thickness cbMargins, int cbWidth, int cbHight)
        {
            fyCBox = new Controls.FiscalYearComboBox(cbMargins, cbWidth, cbHight);

            //P2CuberryDataSet xDataSet = new P2CuberryDataSet();
            //P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fiFiscalYearTableAdapter = new P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();
            //fiFiscalYearTableAdapter.ClearBeforeFill = true;
            //fiFiscalYearTableAdapter.Fill(xDataSet.FiFiscalYear);
            //System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
            //binding.Source = xDataSet.FiFiscalYear;
            //fyCBox.SetBinding(System.Windows.Controls.ComboBox.ItemsSourceProperty, binding);
            
            FindGrid.Children.Add(fyCBox);
        }

        private void addControlStatusOpen(Thickness cbMargins, int cbWidth, int cbHight)
        {
            StatusOpenCheckBox.Name = "StatusOpen";
            StatusOpenCheckBox.Width = cbWidth;
            StatusOpenCheckBox.Height = cbHight;
            StatusOpenCheckBox.Margin = cbMargins; 
            StatusOpenCheckBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            StatusOpenCheckBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;                        
            StatusOpenCheckBox.IsChecked = true;
            StatusOpenCheckBox.Content = P2Translator.GetResource("StatusOpenL");
            FindGrid.Children.Add(StatusOpenCheckBox);
        }

        private void addControlStatusBooked(Thickness cbMargins, int cbWidth, int cbHight)
        {            
            StatusBookedCheckBox.Name = "StatusBooked";
            StatusBookedCheckBox.Width = cbWidth;
            StatusBookedCheckBox.Height = cbHight;
            StatusBookedCheckBox.Margin = cbMargins; 
            StatusBookedCheckBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            StatusBookedCheckBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            StatusBookedCheckBox.IsChecked = true;
            StatusBookedCheckBox.Content = P2Translator.GetResource("StatusBookedL");
            FindGrid.Children.Add(StatusBookedCheckBox);
        }

        private void addControlMonthComboBox(Thickness cbMargins, int cbWidth, int cbHight)
        {
            ArrayList aList = new ArrayList();
            int i;
                        
            for (i = 1; i <= 12; i++)
                aList.Add(i);
            
            MonthComboBox.Name = "MonthComboBox";
            MonthComboBox.Width = cbWidth;
            MonthComboBox.Height = cbHight;
            MonthComboBox.Margin = cbMargins;  
            MonthComboBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            MonthComboBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;            

            MonthComboBox.ItemsSource = aList;            
            FindGrid.Children.Add(MonthComboBox);             
        }

        
        private void addControlAccountLevelComboBox(int MaxLevel, Thickness cbMargins, int cbWidth, int cbHight)
        {
            ArrayList aList = new ArrayList();
            int i;

            for (i = 1; i <= MaxLevel; i++)
                aList.Add(i);

            AccountLevelComboBox.Name = "AccountLevelComboBox";
            AccountLevelComboBox.Width = cbWidth;
            AccountLevelComboBox.Height = cbHight;
            AccountLevelComboBox.Margin = cbMargins;
            AccountLevelComboBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            AccountLevelComboBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            AccountLevelComboBox.ItemsSource = aList;
            FindGrid.Children.Add(AccountLevelComboBox); 
        }

        private void addControlAccountTypeComboBox(Thickness cbMargins, int cbWidth, int cbHight)
        {
            P2CuberryDataSet xDataSet = new P2CuberryDataSet();
            P2CuberryDataSetTableAdapters.FiAccountTypeTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.FiAccountTypeTableAdapter();
            //System.Windows.Forms.BindingSource bindingSource = new System.Windows.Forms.BindingSource();

            tableAdapter.ClearBeforeFill = true;
            tableAdapter.Fill(xDataSet.FiAccountType);
            System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
            
            AccountTypeComboBox.Name = "AccountTypeComboBox";
            AccountTypeComboBox.Width = cbWidth;
            AccountTypeComboBox.Height = cbHight;
            AccountTypeComboBox.Margin = cbMargins;
            AccountTypeComboBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            AccountTypeComboBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            AccountTypeComboBox.SelectedValuePath = "FiAccountTypeID";
            AccountTypeComboBox.DisplayMemberPath = "FiAccountTypeNameAr"; //ToDo: Make it Multilingual!
            
            binding.Source = xDataSet.FiAccountType;
            AccountTypeComboBox.SetBinding(System.Windows.Controls.ComboBox.ItemsSourceProperty, binding);
            FindGrid.Children.Add(AccountTypeComboBox);
        }


        private void addControlAccountNoTexBox(Thickness cbMargins, int cbWidth, int cbHight) 
        {
            AccountNoTexBox.Name = "AccountNoTexBox";
            AccountNoTexBox.Width = cbWidth;
            AccountNoTexBox.Height = cbHight;
            AccountNoTexBox.Margin = cbMargins;
            AccountNoTexBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            AccountNoTexBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            //AccountLevelComboBox.ItemsSource = aList;
            FindGrid.Children.Add(AccountNoTexBox);
        }
                           

        private void addControlAccountSearchTexBox(Thickness cbMargins, int cbWidth, int cbHight)
        {
            //This control comes always in combination with addControlAccountNoComboBox or addControlAccountNoListbox
            AccountNameOrNoSearchTextBox.Name = "AccountNameOrNoSearchTextBox";
            AccountNameOrNoSearchTextBox.Width = cbWidth;
            AccountNameOrNoSearchTextBox.Height = cbHight;
            AccountNameOrNoSearchTextBox.Margin = cbMargins;
            AccountNameOrNoSearchTextBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            AccountNameOrNoSearchTextBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            FindGrid.Children.Add(AccountNameOrNoSearchTextBox);            
        }

        private void addControlDateStart(Thickness cbMargins, int cbWidth, int cbHight) 
        {
            DateStartDatePicker.Name = "DateStartDatePicker";
            DateStartDatePicker.Width = cbWidth;
            DateStartDatePicker.Height = cbHight;
            DateStartDatePicker.Margin = cbMargins;
            DateStartDatePicker.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            DateStartDatePicker.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            FindGrid.Children.Add(DateStartDatePicker);                        
        }

        private void addControlDateEnd(Thickness cbMargins, int cbWidth, int cbHight)
        {
            DateEndDatePicker.Name = "DateEndDatePicker";
            DateEndDatePicker.Width = cbWidth;
            DateEndDatePicker.Height = cbHight;
            DateEndDatePicker.Margin = cbMargins;
            DateEndDatePicker.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            DateEndDatePicker.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            FindGrid.Children.Add(DateEndDatePicker);            
        }

        private void addControlAccountNoCombobox(int FY, Thickness cbMargins, int cbWidth, int cbHight) 
        {
            P2CuberryDataSet xDataSet = new P2CuberryDataSet();
            P2CuberryDataSetTableAdapters.FiAccountTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.FiAccountTableAdapter();
            
            tableAdapter.ClearBeforeFill = true;
            tableAdapter.Fill(xDataSet.FiAccountDataTable, FY);
            System.Windows.Data.Binding binding = new System.Windows.Data.Binding();

            AccountNoComboBox.Name = "AccountNoComboBox";
            AccountNoComboBox.Width = cbWidth;
            AccountNoComboBox.Height = cbHight;
            AccountNoComboBox.Margin = cbMargins;
            AccountNoComboBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            AccountNoComboBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            AccountNoComboBox.SelectedValuePath = "FiAccountID";
            AccountNoComboBox.DisplayMemberPath = "FiAccountNameAr"; //ToDo: Make it Multilingual!

            binding.Source = xDataSet.FiAccountDataTable;
            AccountNoComboBox.SetBinding(System.Windows.Controls.ComboBox.ItemsSourceProperty, binding);
            FindGrid.Children.Add(AccountNoComboBox);
        }
                
        private void addControlTransactionStatusCombobox(Thickness cbMargins, int cbWidth, int cbHight) 
        {
            P2CuberryDataSet xDataSet = new P2CuberryDataSet();
            P2CuberryDataSetTableAdapters.EnterpriseWorkflowStatusTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.EnterpriseWorkflowStatusTableAdapter();
            
            tableAdapter.ClearBeforeFill = true;
            tableAdapter.Fill(xDataSet.EnterpriseWorkflowStatus);
            System.Windows.Data.Binding binding = new System.Windows.Data.Binding();

            TransactionStatusCombobox.Name = "TransactionStatusCombobox";
            TransactionStatusCombobox.Width = cbWidth;
            TransactionStatusCombobox.Height = cbHight;
            TransactionStatusCombobox.Margin = cbMargins;
            TransactionStatusCombobox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            TransactionStatusCombobox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            TransactionStatusCombobox.SelectedValuePath = "StatusID";
            TransactionStatusCombobox.DisplayMemberPath = "StatusNameAr"; //ToDo: Make it Multilingual!

            binding.Source = xDataSet.EnterpriseWorkflowStatus;
            TransactionStatusCombobox.SetBinding(System.Windows.Controls.ComboBox.ItemsSourceProperty, binding);
            FindGrid.Children.Add(TransactionStatusCombobox);
        }


        private void addControlComboWithCheckboxes(int FY, Thickness cbMargins, int cbWidth, int cbHight)
        {
            //http://blogs.microsoft.co.il/blogs/justguy/archive/2009/01/19/wpf-combobox-with-checkboxes-as-items-it-will-even-update-on-the-fly.aspx

            P2CuberryDataSet xDataSet = new P2CuberryDataSet();
            P2CuberryDataSetTableAdapters.FiAccountTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.FiAccountTableAdapter();

            tableAdapter.ClearBeforeFill = true;
            tableAdapter.Fill(xDataSet.FiAccountDataTable, FY);
            System.Windows.Data.Binding binding = new System.Windows.Data.Binding();

            MyComboWithCheckboxes.Name = "MyComboWithCheckboxes";
            MyComboWithCheckboxes.Width = cbWidth;
            MyComboWithCheckboxes.Height = cbHight;
            MyComboWithCheckboxes.Margin = cbMargins;
            MyComboWithCheckboxes.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            MyComboWithCheckboxes.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            ObservableNodeList itemSource = new ObservableNodeList();
            itemSource.Add(new Node("Willa"));
            itemSource.Add(new Node("Isak"));
            itemSource.Add(new Node("Victor"));
            itemSource.Add(new Node("Jules"));
            
            MyComboWithCheckboxes.ItemsSource = itemSource;
            //binding.Source = xDataSet.FiAccountDataTable;
            //MyComboWithCheckboxes.SetBinding(System.Windows.Controls.ListBox.ItemsSourceProperty, binding);
            
            FindGrid.Children.Add(MyComboWithCheckboxes);                        
        }


        private void addControlAccountNoListbox(int FY, Thickness cbMargins, int cbWidth, int cbHight) 
        {
            P2CuberryDataSet xDataSet = new P2CuberryDataSet();
            P2CuberryDataSetTableAdapters.FiAccountTableAdapter tableAdapter = new P2CuberryDataSetTableAdapters.FiAccountTableAdapter();

            tableAdapter.ClearBeforeFill = true;
            tableAdapter.Fill(xDataSet.FiAccountDataTable, FY);
            System.Windows.Data.Binding binding = new System.Windows.Data.Binding();

            AccountNoListBox.Name = "AccountNoListBox";
            AccountNoListBox.Width = cbWidth;
            AccountNoListBox.Height = cbHight;
            AccountNoListBox.Margin = cbMargins;
            AccountNoListBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            AccountNoListBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            AccountNoListBox.SelectedValuePath = "FiAccountID";
            AccountNoListBox.DisplayMemberPath = "FiAccountNameAr"; //ToDo: Make it multilingual

            //accountNoListBox.ItemsSource = aList;
            binding.Source = xDataSet.FiAccountDataTable;
            AccountNoListBox.SetBinding(System.Windows.Controls.ListBox.ItemsSourceProperty, binding);
            AccountNoListBox.SelectionMode = System.Windows.Controls.SelectionMode.Multiple;    
            
            FindGrid.Children.Add(AccountNoListBox);
        }

        

        //private void OnAccountNameChangedUpdateAccountNoComboBox(object sender, EventArgs e)
        //{
        //    if (this.FiscalYearComboBox.SelectedIndex == -1 || String.IsNullOrEmpty(this.accountNameTextBox.Text))
        //        return;

        //    P2CuberryDataSetTableAdapters.FiAccountTableAdapter fiAccountTableAdapter = new ReportViewer.P2CuberryDataSetTableAdapters.FiAccountTableAdapter();
        //    System.Windows.Forms.BindingSource fyBindingSource = new System.Windows.Forms.BindingSource(this.components);

        //    ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).BeginInit();

        //    accountNoComboBox.DataSource = fyBindingSource;
        //    DataRowView fiYearRow = (DataRowView)this.FiscalYearComboBox.SelectedItem;
        //    int fiYear = Convert.ToInt32(fiYearRow["FiscalYearID"].ToString());

        //    fyBindingSource.DataMember = "FiAccountDataTable";
        //    fyBindingSource.DataSource = this.P2CuberryDataSet;

        //    ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).EndInit();

        //    fiAccountTableAdapter.ClearBeforeFill = true;
        //    this.P2CuberryDataSet.FiAccountDataTable.DataSet.EnforceConstraints = false;

        //    fiAccountTableAdapter.FillByAccountName(this.P2CuberryDataSet.FiAccountDataTable, fiYear, this.accountNameTextBox.Text.Trim());
        //}

        //private void OnFiscalYearChangedUpdateAccountNoListBox(object sender, EventArgs e)
        //{
        //    if (this.FiscalYearComboBox.SelectedIndex == -1)
        //        return;

        //    P2CuberryDataSetTableAdapters.FiAccountTableAdapter fiAccountTableAdapter = new ReportViewer.P2CuberryDataSetTableAdapters.FiAccountTableAdapter();
        //    System.Windows.Forms.BindingSource fyBindingSource = new System.Windows.Forms.BindingSource(this.components);

        //    ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).BeginInit();

        //    accountNoListBox.DataSource = fyBindingSource;
        //    DataRowView fiYearRow = (DataRowView)this.FiscalYearComboBox.SelectedItem;
        //    int fiYear = Convert.ToInt32(fiYearRow["FiscalYearID"].ToString());

        //    fyBindingSource.DataMember = "FiAccountDataTable";
        //    fyBindingSource.DataSource = this.P2CuberryDataSet;

        //    ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).EndInit();

        //    fiAccountTableAdapter.ClearBeforeFill = true;
        //    this.P2CuberryDataSet.FiAccountDataTable.DataSet.EnforceConstraints = false;

        //    fiAccountTableAdapter.Fill(this.P2CuberryDataSet.FiAccountDataTable, fiYear);

        //}

        private void addControlDocumentNoTextBox(Thickness cbMargins, int cbWidth, int cbHight)
        {
            DocumentNoTextBox.Name = "DocumentNoTextBox";
            DocumentNoTextBox.Width = cbWidth;
            DocumentNoTextBox.Height = cbHight;
            DocumentNoTextBox.Margin = cbMargins;
            DocumentNoTextBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            DocumentNoTextBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            FindGrid.Children.Add(DocumentNoTextBox);
        }

        private void addControlDescriptionHeaderTextBox(Thickness cbMargins, int cbWidth, int cbHight)
        {
            DescriptionHeaderTextBox.Name = "DescriptionHeaderTextBox";
            DescriptionHeaderTextBox.Width = cbWidth;
            DescriptionHeaderTextBox.Height = cbHight;
            DescriptionHeaderTextBox.Margin = cbMargins;
            DescriptionHeaderTextBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            DescriptionHeaderTextBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            FindGrid.Children.Add(DescriptionHeaderTextBox);
        }

        private void addControlDescriptionItemTextBox(Thickness cbMargins, int cbWidth, int cbHight)
        {
            DescriptionItemTextBox.Name = "DescriptionItemTextBox";
            DescriptionItemTextBox.Width = cbWidth;
            DescriptionItemTextBox.Height = cbHight;
            DescriptionItemTextBox.Margin = cbMargins;
            DescriptionItemTextBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            DescriptionItemTextBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            FindGrid.Children.Add(DescriptionItemTextBox);            
        }

        #endregion


        #region ComboWithCheckBox

        public class Node
        {
            public Node(string n) { Title = n; }
            public string Title { get; set; }
            public bool IsSelected { get; set; }
        }

        public class ObservableNodeList : ObservableCollection<Node>
        {
            public ObservableNodeList()
            {

            }

            public override string ToString()
            {
                StringBuilder outString = new StringBuilder();
                foreach (Node s in this.Items)
                {
                    if (s.IsSelected == true)
                    {
                        outString.Append(s.Title);
                        outString.Append(',');
                    }
                }
                return outString.ToString().TrimEnd(new char[] { ',' });
            }
        }

        #endregion




    }
}

